package com.owen.he.jee.model;

import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import lombok.Data;
import lombok.EqualsAndHashCode;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.owen.he.jee.utils.OrderIdSerializer;


/*
 * 操作日志记录
 * @Author tony.zhang
 */
@Entity
@Table(name="operation_log")
@Data
@EqualsAndHashCode(callSuper=false)
public class OperationLog {
	private static final long serialVersionUID = 1L;
	
	/*
	 * 主键
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@JsonSerialize(using = OrderIdSerializer.class)
	private long id;
	
	/*
	 * HR账户Id
	 */
	@Column(name="account_id")
	private int accountId;
	
	/*
	 * 操作时间
	 */
	@Column(name = "operation_time", columnDefinition = "timestamp not null default now()")
	private Timestamp operationTime;
	
	/*
	 * 操作类型(由枚举值OperationTypeEnum决定)
	 */
	@Column(name = "operation_type")
	private int operationType;
	
	public static enum OperationTypeEnum {
	
		addBrokderProvier(1,"新增代理商","id:%s,name:%s");
		
		/*
		 * operationType
		 */
		int id;
		
		/*
		 * 操作描述
		 */
		String desc;
		
		/*
		 * content规则通配符
		 */
		String descPatern;
		
		public String getDescPatern() {
			return descPatern;
		}
		public int getId() {
			return id;
		}

		public String getDesc() {
			return desc;
		}
		OperationTypeEnum(int id, String desc, String descPattern) {
			this.id = id;
			this.desc = desc;
			this.descPatern = descPattern;
		}
		
		public static final OperationTypeEnum operationType(int operationType) {
			final OperationTypeEnum[] values = OperationTypeEnum.values();
			for (OperationTypeEnum operationTypeEnum : values) {
				if (operationTypeEnum.id == operationType) {
					return operationTypeEnum;
				}
			}
			throw new IllegalArgumentException("Unknow operation type '" + operationType + "'");
		}
	}
	
	
	public OperationLog() {
	}
	
	public OperationLog(OperationTypeEnum type, int accountId, Object... args) {
		this.operationType = type.id;
		this.accountId = accountId;
		this.operationTime = new Timestamp(System.currentTimeMillis());
	}
}
